<template>
	<view>
		<view v-if="!errorNetwork">
			<view class="page-index" :class="{ bgf: navIndex > 0 }">
				<!-- 首页头部搜索部分 -->
				<!-- #ifdef H5 -->
				<view class="header">
					<view class="serch-wrapper flex acea-row row-between-wrapper">
<!--						<view v-if="logoUrl" class="logo">-->
<!--							&lt;!&ndash; <image v-if="!logoUrl" class="logo" src="/static/images/crmeb.png"></image> &ndash;&gt;-->
<!--							<image :src="logoUrl" mode=""></image>-->
<!--						</view>-->
						<navigator url="/pages/columnGoods/goods_search/index" :class="logoUrl ? 'input' : 'uninput'" hover-class="none">
							<text class="iconfont icon-xiazai5"></text>
							搜索商品
						</navigator>

						<navigator class="btn" url="/pages/chat/customer_list/index?type=0" hover-class="none">
							<view class="iconfont icon-xiaoxi"></view>
							<text class="iconnum bg-color-red" v-if="userInfo.total_unread">{{ userInfo.total_unread }}</text>
						</navigator>
					</view>

<!--					<tabNav class="tabNav" :class="{ fixed: isFixed }" :tabTitle="navTop" @changeTab="changeTab"></tabNav>-->
				</view>
				<!-- #endif -->

				<!-- #ifdef MP || APP-PLUS -->
				<view class="mp-header">
					<view class="sys-head" view :style="{ height: statusBarHeight }"></view>
					<view class="serch-box" view style="height: 43px;">
						<view class="serch-wrapper flex" style="padding-left: 30rpx;">
<!--							<view v-if="logoUrl" class="logo"><image :src="logoUrl" mode=""></image></view>-->
              <view class="iconfont icon-xiangzuo" @click="goback" style="color: #000;margin-right: 30px;"></view>
							<navigator url="/pages/columnGoods/goods_search/index" :class="logoUrl ? 'input' : 'uninput'" hover-class="none">
								<text class="iconfont icon-xiazai5"></text>
								搜索商品
							</navigator>
						</view>
					</view>
<!--					<tabNav class="tabNav" :tabTitle="navTop" @changeTab="changeTab"></tabNav>-->
				</view>
				<!-- #endif -->

				<!-- 首页头部搜索部分结束 -->

				<!-- 首页展示 -->
				<view class="page_content" v-if="navIndex == 0" :style="{ marginTop: mpHeight + 'px' }">
					<!-- #ifdef MP -->
					<!-- <view class="mp-bg"></view> -->
					<!-- #endif -->
					<!-- banner 开始 -->
					<view style="display: none" class="swiper" v-if="imgUrls.length">
						<swiper
							indicator-dots="true"
							:autoplay="true"
							:circular="circular"
							:interval="interval"
							:duration="duration"
							indicator-color="#E4E4E4"
							indicator-active-color="#E93323"
							previous-margin="40rpx"
							next-margin="40rpx"
							:current="swiperCur"
							@change="swiperChange"
						>
							<block v-for="(item, index) in imgUrls" :key="index">
								<swiper-item :class="{ active: index == swiperCur }">
									<navigator :url="item.url" class="slide-navigator acea-row row-between-wrapper" hover-class="none"><image :src="item.pic" class="slide-image"></image></navigator>
								</swiper-item>
							</block>
						</swiper>
					</view>
					<!-- banner 结束 -->
					<!-- menu 商品品类列表开始-->
					<view style="display: none"  class="nav acea-row" v-if="menus.length">
						<block v-for="(item, index) in menus" :key="index">
							<view class="item" @click="goMenuDetail(item)">
								<view class="pictrue"><image :src="item.pic"></image></view>
								<view class="menu-txt area-row">{{ item.name }}</view>
							</view>
						</block>
					</view>
					<!-- menu 商品品类列表结束-->
					<!-- 后端配置跳转用宣传图片 -->
					<navigator style="display: none"  v-if="ad.home_ad_pic" class="ad" :url="ad.home_ad_url" hover-class="none"><image mode="" :src="ad.home_ad_pic"></image></navigator>
					<!-- 后端配置跳转用宣传图片结束 -->
					<!--秒杀 开始-->
					<view style="display: none"  class="main" v-if="spikeList.length > 0">
						<view class="seckill-count">
							<view class="spike-bd">
								<view class="title line1">限时秒杀</view>
								<view class="spike-distance">
									<text class="text bg-red">距结束</text>
									<countDown :is-day="false" :tip-text="' '" :day-text="' '" :hour-text="':'" :minute-text="':'" :second-text="' '" :datatime="datatime"></countDown>
								</view>
								<navigator url="/pages/activity/goods_seckill/index" class="more-btn" hover-class="none">
									更多
									<text class="iconfont icon-jiantou" hover-class="none"></text>
								</navigator>
							</view>
							<view class="spike-wrapper">
								<scroll-view scroll-x="true" style="white-space: nowrap; display: flex" show-scrollbar="false">
									<navigator
										class="spike-item"
										v-for="(item, index) in spikeList"
										:key="index"
										:url="'/pages/activity/goods_seckill_details/index?id=' + item.product_id + '&time=' + item.stop + ''"
										hover-class="none"
									>
										<view class="img-box"><image :src="item.image" mode=""></image></view>
										<view class="info">
											<view class="name line1">{{ item.store_name }}</view>
											<view class="stock-box">
												<view class="grabbed" :style="'width:' + item.sales + ';'"></view>
												<text class="stock-sales">{{ item.sales }}</text>
											</view>
											<view class="price-box">
												<text class="price">
													<text>￥</text>
													{{ item.price }}
												</text>
												<text class="old-price">
													<text>￥</text>
													{{ item.ot_price }}
												</text>
											</view>
										</view>
									</navigator>
								</scroll-view>
							</view>
						</view>
					</view>
					<!--秒杀 结束-->

					<!-- 拼团 开始-->
					<view style="display: none"  v-if="combinationList.length > 0" class="main">
						<view class="combination-count">
							<view class="spike-bd">
								<view class="title line1">拼团活动</view>
								<navigator url="/pages/activity/combination/index" class="more-btn" hover-class="none">
									更多
									<text class="iconfont icon-jiantou" hover-class="none"></text>
								</navigator>
							</view>
							<view class="combination_wrapper">
								<view class="spike-wrapper">
									<block class=" acea-row row-between-wrapper combination">
										<view class="combination-item" v-for="(item, index) in combinationList" :key="index" hover-class="none" @click="goCombinDetail(item)">
											<view class="info">
												<view class="price-box combination-price">
													<view class="name line1">{{ item.product.store_name }}</view>
													<text class="price">
														<text>￥</text>
														{{ item.price }}
													</text>
													<text class="gocom_btn">
														去拼团
														<text class="iconfont icon-jiantou"></text>
													</text>
												</view>
											</view>
											<view class="img-box"><image :src="item.product.image" mode=""></image></view>
										</view>
										<view v-if="combinationList.length == 1" class="combination-item" @click="goCombinDetail(combinationList[0])">
											<view class="info">
												<view class="price-box combination-price">
													<view class="name line1">{{ combinationList[0].product.store_name }}</view>
													<text class="price">
														<text>￥</text>
														{{ combinationList[0].price }}
													</text>
													<text class="gocom_btn">
														去拼团
														<text class="iconfont icon-jiantou"></text>
													</text>
												</view>
											</view>
											<view class="img-box"><image :src="combinationList[0].product.image" mode=""></image></view>
										</view>
										<view v-if="combinationList.length == 1" class="combination-item" @click="goCombinDetail(combinationList[0])">
											<view class="info">
												<view class="price-box combination-price">
													<view class="name line1">{{ combinationList[0].product.store_name }}</view>
													<text class="price">
														<text>￥</text>
														{{ combinationList[0].price }}
													</text>
													<text class="gocom_btn">
														去拼团
														<text class="iconfont icon-jiantou"></text>
													</text>
												</view>
											</view>
											<view class="img-box"><image :src="combinationList[0].product.image" mode=""></image></view>
										</view>
										<view v-if="combinationList.length == 2" class="combination-item" @click="goCombinDetail(combinationList[1])">
											<view class="info">
												<view class="price-box combination-price">
													<view class="name line1">{{ combinationList[1].product.store_name }}</view>
													<text class="price">
														<text>￥</text>
														{{ combinationList[1].price }}
													</text>
													<text class="gocom_btn">
														去拼团
														<text class="iconfont icon-jiantou"></text>
													</text>
												</view>
											</view>
											<view class="img-box"><image :src="combinationList[1].product.image" mode=""></image></view>
										</view>
									</block>
								</view>
							</view>
						</view>
					</view>
					<!-- 拼团 结束-->

					<!-- #ifdef MP -->
					<!--直播 开始 -->
					<view style="display: none"  class="main" v-if="liveList.length > 0">
						<view class="live-count">
							<view>
								<!-- 直播 -->
								<block>
									<view class="spike-bd">
										<view class="title line1">直播专场</view>
										<navigator url="/pages/activity/liveBroadcast/index" class="more-btn" hover-class="none">
											更多
											<text class="iconfont icon-jiantou" hover-class="none"></text>
										</navigator>
									</view>

									<view class="live-wrapper mores">
										<scroll-view scroll-x="true" style="white-space: nowrap; display: flex">
											<view class="item" v-for="(item, index) in liveList" :key="index">
												<navigator hover-class="none" :url="item.link">
													<view
														class="live-top"
														:style="'background:' + (item.live_status == 101 ? playBg : item.live_status != 101 && item.live_status != 102 ? endBg : notBg) + ';'"
														:class="item.live_status == 102 ? 'playRadius' : 'notPlayRadius'"
													>
														<block v-if="item.live_status == 101">
															<image src="/static/images/live-01.png" mode=""></image>
															<text>直播中</text>
														</block>
														<block v-if="item.live_status == 103 && item.replay_status === 1">
															<image src="/static/images/live-02.png" mode=""></image>
															<text>回放</text>
														</block>
														<block v-if="(item.live_status != 101 && item.live_status != 102 && item.live_status != 103) || (item.live_status == 103 && item.replay_status == 0)">
															<image src="/static/images/live-02.png" mode=""></image>
															<text>已结束</text>
														</block>
														<block v-if="item.live_status == 102">
															<image src="/static/images/live-03.png" mode=""></image>
															<text>预告</text>
														</block>
													</view>
													<view v-if="item.live_status == 101 || item.live_status == 102" class="broadcast-time">{{ item.show_time }}</view>
													<image :src="item.share_img"></image>
													<!-- <view class="live-title">{{ item.live_status }}</view> -->
												</navigator>
											</view>
										</scroll-view>
									</view>
								</block>

							</view>
						</view>

					</view>
					<!-- 直播模块 结束 -->
					<!-- #endif -->

					<!--预售 开始-->
					<presell style="display: none"  v-if="presellList.length > 0" :presellList="presellList"></presell>
					<!--预售 结束 -->

					<!--助力-->
					<view style="display: none"  class="main" v-if="assistList.length > 0">
						<view class="assist-count">
							<view class="spike-bd">
								<view class="title line1">助力活动</view>
								<view v-if="assistUserList.length > 0" class="activity_pic">
									<view v-for="(item, index) in assistUserList" class="picture"><span class="avatar" :style="'background-image: url(' + item.avatar_img + ')'"></span></view>
									<text class="pic_count">{{ assistUserCount }}人助力成功</text>
								</view>
								<navigator url="/pages/activity/assist/index" class="more-btn" hover-class="none">
									更多
									<text class="iconfont icon-jiantou" hover-class="none"></text>
								</navigator>
							</view>
							<view class="wapper_count">
								<view class="spike-wrapper">
									<scroll-view scroll-x="true" style="white-space: nowrap; display: flex" show-scrollbar="false">
										<view class="spike-item assist-item" v-for="(item, index) in assistList" :key="index" @click="handleAssist(item.product_assist_id)">
											<view class="img-box">
												<image :src="item.product.image" mode=""></image>
												<text class="participants">{{ item.user_count }}人参与</text>
											</view>
											<view class="assist-info">
												<view class="price-box presell-price">
													<view class="name line1">{{ item.store_name }}</view>
													<text class="price">
														<text class="assist_price">助力价</text>
														<text>￥</text>
														{{ item.assistSku[0].assist_price }}
													</text>
												</view>
												<button class="initiate_btn">发起助力</button>
											</view>
										</view>
									</scroll-view>
								</view>
							</view>
						</view>
					</view>
					<!--助力结束-->
					<view class="main">
						<!-- 热点菜单 -->
						<hot-menu :hot="hot"></hot-menu>
						<!-- 热点菜单结束 -->

						<!-- 品牌好店 -->
						<brand-store style="display: none"  v-if="brandList.length && hide_mer_status != 1" :brandList="brandList" :hide_mer_status="hide_mer_status"></brand-store>
						<!-- 品牌好店结束 -->


						<!-- 首页推荐 -->
						<view  class="index-product-wrapper">
							<!-- 首发新品 -->
							<recommend :hostProduct="hostProduct" :indexP="true" :isLogin="isLogin"></recommend>
							<view class="loadingicon acea-row row-center-wrapper" v-if="hostProduct.length > 0">
								<text class="loading iconfont icon-jiazai" :hidden="hotLoading == false"></text>
								{{ hotTitle }}
							</view>
						</view>

					</view>

				</view>
				<!-- 分类页 -->

				<view class="productList" v-if="navIndex > 0" :style="'margin-top:' + prodeuctTop + 'px;'">
					<view class="sort acea-row" :class="sortList.length ? '' : 'no_pad'" :style="{ marginTop: sortMarTop + 'px' }">
						<navigator
							hover-class="none"
							:url="'/pages/columnGoods/goods_list/index?id=' + item.store_category_id + '&title=' + item.cate_name"
							class="item"
							v-for="(item, index) in sortList"
							:key="index"
						>
							<view class="pictrue"><image :src="item.pic"></image></view>
							<view class="text">{{ item.cate_name }}</view>
						</navigator>
						<view class="item" @click="bindMore(item)" v-if="sortList.length">
							<view class="pictrues acea-row row-center-wrapper"><text class="iconfont icon-gengduo1"></text></view>
							<view class="text" style="margin-top: 22rpx;">更多</view>
						</view>
					</view>
					<block v-if="sortProduct.length > 0">
						<view class="list acea-row row-between-wrapper">
							<navigator @tap="goDetails(item)" class="item" v-for="(item, index) in sortProduct" :key="index">
								<view class="pictrue"><image :src="item.image"></image></view>
								<view class="text">
									<view class="name line1">
										<text v-if="item.merchant.type_name && item.product_type == 0" class="font-bg-red">{{ item.merchant.type_name }}</text>
										<text v-else-if="item.merchant.is_trader && item.product_type == 0" class="font-bg-red">自营</text>
										<span v-if="item.product_type != 0" :class="'font_bg-red type' + item.product_type">
											{{ item.product_type == 1 ? '秒杀' : item.product_type == 2 ? '预售' : item.product_type == 3 ? '助力' : item.product_type == 4 ? '拼团' : '' }}
										</span>
										{{ item.store_name }}
									</view>
									<view class="acea-row row-middle">
										<view class="money font-color-red">
											￥
											<text class="num">{{ item.price }}</text>
										</view>
										<text class="coupon font-color-red" v-if="item.issetCoupon">领券</text>
									</view>
								</view>
							</navigator>
							<view class="loadingicon acea-row row-center-wrapper" v-if="sortProduct.length > 0 || sortProductLoading">
								<text class="loading iconfont icon-jiazai" :hidden="loading == false"></text>
								{{ loadTitle }}
							</view>
						</view>
					</block>
					<block v-if="sortProduct.length == 0">
						<view class="noCommodity">
							<view class="pictrue" style="margin: 0 auto;"><image src="/static/images/noShopper.png"></image></view>
							<recommend :hostProduct="hostProduct"></recommend>
						</view>
					</block>
				</view>

			</view>
		</view>
		<view v-else>
			<view class="error-network">
				<image src="/static/images/error-network.png"></image>
				<view class="title">网络连接断开</view>
				<view class="con">
					<view class="label">请检查情况：</view>
					<view class="item">· 在设置中是否已开启网络权限</view>
					<view class="item">· 当前是否处于弱网环境</view>
					<view class="item">· 版本是否过低，升级试试吧</view>
				</view>
				<view class="btn" @click="reconnect">重新连接</view>
			</view>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view class="privacy-wrapper" v-if="privacyStatus">
			<view class="privacy-box">
				<view class="title">服务协议与隐私政策</view>
				<view class="content">
					请务必审慎阅读、充分理解“服务协议与 隐私政策”各条款，包括但不限于：为了 向你提供即时通讯、内容分享等服务，我 们需要收集你的设备信息、操作日志等个
					人信息。你可以在“设置”中查看、变更、 删除个人信息并管理你的授权。
					<br />
					你可以阅读
					<navigator url="/pages/users/privacy/index">《服务协议与隐私政策》</navigator>
					了解 详细信息。如你同意，请点击“我同意”开始接受我们的服务。
				</view>
				<view class="btn-box">
					<view class="btn-item" @click="confirmApp">我同意</view>
					<view class="btn" @click="closeModel">随便逛逛</view>
				</view>
			</view>
		</view>
		<!-- #endif -->

		<!-- #ifdef MP -->
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse" :isGoIndex="false"></authorize>
		<!-- #endif -->
	</view>
</template>
<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
var statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
let app = getApp();
import { getUserInfo } from '@/api/user.js';
import { getIndexData, getCoupons } from '@/api/api.js';
// #ifdef MP-WEIXIN
import { getTemlIds } from '@/api/api.js';
import { SUBSCRIBE_MESSAGE, TIPS_KEY } from '@/config/cache';
import { getLiveList } from '@/api/store.js';
// #endif

import { getShare, follow, getconfig } from '@/api/public.js';
import { getSeckillIndexTime } from '@/api/activity.js';

import goodList from '@/components/goodList';
import promotionGood from '@/components/promotionGood';
import couponWindow from '@/components/couponWindow';
import { goShopDetail } from '@/libs/order.js';
import { mapGetters } from 'vuex';
import tabNav from '@/components/tabNav.vue';
import countDown from '@/components/countDown';
import { getCategoryList, getProductslist, getProductHot, storeCategory, storeMerchantList } from '@/api/store.js';
import { getPresellList, getSeckillList, getAssistList, initiateAssistApi, assistUserData, getCombinationList } from '@/api/activity.js';
import { openBargainSubscribe } from '@/utils/SubscribeMessage.js';
import { setVisit, spread } from '@/api/user.js';
import recommend from '@/components/recommend';
// #ifdef MP
import authorize from '@/components/Authorize';
// #endif
import { silenceBindingSpread } from '@/utils';
import history from '@/mixins/history';
import { toLogin } from '@/libs/login.js';
import shareScence from '@/libs/spread';
import presell from './component/presell.vue';
import hotMenu from './component/hotMenu.vue';
import brandStore from './component/brandStore.vue';

export default {
	computed: mapGetters(['isLogin', 'uid']),
	mixins: [history],
	components: {
		presell, // 预售组件
		hotMenu, // 热点菜单组件
		brandStore, // 热门店铺
		tabNav,
		goodList,
		promotionGood,
		couponWindow,
		countDown,
		recommend,
		// #ifdef MP
		authorize
		// #endif
	},
	data() {
		return {
			privacyStatus: false,
			errorNetwork: false,
			countDownHour: '00',
			countDownMinute: '00',
			countDownSecond: '00',
			datatime: '',
			ad: '',
			userInfo: '',
			loading: false,
			isAuto: false, //没有授权的不会自动授权
			isShowAuth: false, //是否隐藏授权
			statusBarHeight: statusBarHeight,
			navIndex: 0,
			navTop: [],
			subscribe: false,
			followUrl: '',
			followHid: true,
			followCode: false,
			logoUrl: app.globalData.site_logo,
			// logoUrl: "",
			imgUrls: [],
			hot: [],
			sortList: [],
			itemNew: [],
			menus: [],
			bastInfo: '',
			fastInfo: '',
			firstInfo: '',
			firstList: [],
			salesInfo: '',
			likeInfo: [],
			benefit: [],
			indicatorDots: false,
			circular: true,
			autoplay: true,
			interval: 3000,
			duration: 500,
			window: false,
			iShidden: false,
			navH: '',
			newGoodsBananr: '',
			couponList: [],
			lovely: [],
			spikeList: [], //秒杀
			liveList: [], //直播
			presellList: [], //预售
			assistList: [], //助力
			assistUserList: [], //已助力数据
			assistUserCount: '',
			combinationList: [],
			hotList: [
				{
					pic: '/static/images/hot_001.png'
				},
				{
					pic: '/static/images/hot_002.png'
				},
				{
					pic: '/static/images/hot_003.png'
				}
			],
			spikeList: [],
			bargList: [],
			ProductNavindex: 0,
			marTop: 0,
			datatime: 0,
			childID: 0,
			loadend: false,
			loading: false,
			loadTitle: '加载更多',
			sortProduct: [],
			where: {
				pid: 0,
				page: 1,
				limit: 6
			},
			is_switch: true,
			hostProduct: [],
			hotPage: 1,
			hotLimit: 8,
			hotScroll: true,
			hotLoading: false,
			hotTitle: '加载更多',
			explosiveMoney: [],
			prodeuctTop: 0,
			pinkInfo: '',
			searchH: 0,
			isFixed: false,
			goodScroll: true, //精品推荐开关
			params: {
				//精品推荐分页
				page: 1,
				limit: 10
			},
			tempArr: [], //精品推荐临时数组
			pageInfo: '', // 精品推荐全数据
			site_name: app.globalData.site_name, //首页title
			swiperCur: 0,
			brandList: [],
			d: '',
			h: '',
			m: '',
			s: '',
			sum_h: '',
			endBg: 'linear-gradient(#666666, #999999)',
			notBg: 'rgb(26, 163, 246)',
			playBg: 'linear-gradient(#FF0000, #FF5400)',
			hide_mer_status: 1,
			sortMarTop: 0,
			globalDatas: {},
			mpHeight: 0,
			currSpid: '',
			mer_location: '',
			share_title: '',
			_options:{},
		};
	},
	/**
	 * 用户点击右上角分享
	 */
	// #ifdef MP
	onShareAppMessage: function() {
		let that = this;
		wx.showShareMenu({
			withShareTicket: true,
			menus: ['shareAppMessage', 'shareTimeline']
		});
		return {
			title: that.share_title,
			path: '/pages/index/index?spid=' + that.uid
		};
	},
	onShareTimeline: function() {
		let that = this;
		return {
			title: that.share_title,
			query: {
				spid: that.uid
			},
			imageUrl: ''
		};
	},
	// #endif
	onLoad(options) {
		this._options = options;
		// #ifdef APP-PLUS
		const pages = getCurrentPages();
		const page = pages[pages.length - 1];
		const currentWebview = page.$getAppWebview();
		currentWebview.setStyle({
		  pullToRefresh: {
		    support: !this.isSupport,
		    style: plus.os.name === 'Android' ? 'circle' : 'default'
		  }
		});
		this.isSupport = !this.isSupport;
		// #endif
		this.pageLoad(options);
	},
	onShow() {
		this.getConfig();
		this.syncHeight();
	},
	onReady() {
		this.syncHeight();
	},
	watch: {
		globalDatas(nVal, oVal) {
			// #ifdef H5
			this.ShareInfo(nVal);
			// #endif
		},
		privacyStatus(n) {
			if (n) {
				uni.hideTabBar();
			} else {
				uni.showTabBar();
			}
		}
	},
	onPullDownRefresh(){
		setTimeout(()=> {
			uni.stopPullDownRefresh();
		}, 100);
		this.reconnect();
	},
	methods: {
    goback(){
      uni.navigateBack({delta: 1})
    },
		pageLoad(options){
			let that = this;
			if (options.spid) {
				that.currSpid = options.spid;
				app.globalData.spid = options.spid;
			}
			// #ifdef APP-PLUS
			try {
				let val = uni.getStorageSync('privacyStatus') || false;
				if (!val) {
					this.privacyStatus = true;
				}
			} catch (e) {}
			this.snycNetWork();

			// #endif

			// #ifdef MP
			if (options.scene) {
				let value = that.$util.getUrlParams(decodeURIComponent(options.scene));
				if (value.id) options.id = value.id;
				//记录推广人uid
				if (value.spid) {
					that.currSpid = value.spid;
					app.globalData.spid = value.spid;
				}
			}
			// #endif
			shareScence(that.currSpid, that.isLogin);
			uni.getLocation({
				type: 'wgs84',
				success: function(res) {
					try {
						uni.setStorageSync('user_latitude', res.latitude);
						uni.setStorageSync('user_longitude', res.longitude);
					} catch {}
				}
			});

			// #ifdef MP
			// 获取小程序头部高度
			this.navH = app.globalData.navHeight;
			let info = uni.createSelectorQuery().select('.mp-header');
			info
				.boundingClientRect(function(data) {
					that.marTop = data.height;
				})
				.exec();
			// #endif
			// #ifndef MP
			this.navH = 0;
			// #endif
			this.isLogin && silenceBindingSpread();

			// this.setVisit()
			Promise.all([
				this.getIndexConfig(),
				this.storeMerchant(),
				this.get_host_product(),
				this.getSpeckillCutTime(),
				this.getSpikeProduct(),
				this.getCombinationProduct(),
				this.getPresellProduct(),
				this.getAssistProduct(),
				this.getAssistUserCount()
			]);
			// #ifdef MP
			this.getLiveList();
			// #endif
			if (this.isLogin) {
				this.getUserInfo();
				// #ifdef MP
				this.getHistory();
				// #endif
			}
		},
		// 重新链接
		reconnect() {
			uni.getNetworkType({
				success: res => {
					this.errorNetwork = res.networkType === 'none';
					if(!this.errorNetwork){
						this.pageLoad(this._options);
					}
				}
			});
		},
		syncHeight() {
			let self = this;
			// #ifdef MP || APP-PLUS
			setTimeout(res => {
				let info = uni.createSelectorQuery().select('.mp-header');
				info
					.boundingClientRect(function(data) {
						//data - 各种参数
						self.mpHeight = data.height;
					})
					.exec();
			}, 800);
			// #endif
		},
		// #ifdef APP-PLUS
		snycNetWork() {
			uni.getNetworkType({
				success: res => {
					this.errorNetwork = res.networkType === 'none';
				}
			});
		},
		// 同意隐私协议
		confirmApp() {
			uni.setStorageSync('privacyStatus', true);
			this.privacyStatus = false;
		},
		// 关闭Model
		closeModel() {
			this.privacyStatus = false;
		},
		// #endif
		// 微信登录回调
		onLoadFun: function(e) {
			this.isShowAuth = false;
		},
		setViewport(content) {
			const meta = document.querySelector('meta[name=viewport]');
			if (!meta) return;
			meta.setAttribute('content', content);
		},
		// 菜单详情
		goMenuDetail(item) {
			// let url = this.$util.stringIntercept(item.url, 0, "\?")
			if (item.url == '/pages/goods_cate/goods_cate') {
				let data = this.$util.stringIntercept(item.url, 1, '\?');
				data = this.$util.stringIntercept(data, 1, '\=');
				uni.setStorageSync('storeIndex', data);
				uni.switchTab({
					url: '/pages/goods_cate/goods_cate'
				});
				// try {

				// } catch (e) {}
			} else {
				uni.navigateTo({
					url: item.url
				});
			}
		},
		getConfig() {
			// 获取配置
			getconfig()
				.then(res => {
					let self = this;
					this.globalDatas = res.data;
					this.logoUrl = res.data.site_logo;
					this.site_name = res.data.site_name;
					this.hide_mer_status = res.data.hide_mer_status;
					this.mer_location = res.data.mer_location;
					this.share_title = res.data.share_title;
					//#ifndef APP-PLUS
					uni.setNavigationBarTitle({
						title: self.site_name
					});
					//#endif
					uni.$emit('configData', res.data);
				})
				.catch(err => {});
		},
		// 分类页更多
		bindMore(item) {
			console.log(this.navTop[this.navIndex]);
			try {
				uni.setStorageSync('storeIndex', this.navTop[this.navIndex].pid);
				uni.switchTab({
					url: '/pages/goods_cate/goods_cate'
				});
			} catch (e) {}
		},
		goDetails(item) {
			goShopDetail(item, this.uid).then(res => {
				if (this.isLogin) {
					initiateAssistApi(item.activity_id)
						.then(res => {
							let id = res.data.product_assist_set_id;
							uni.hideLoading();
							// #ifndef MP
							uni.navigateTo({
								url: '/pages/activity/assist_detail/index?id=' + id
							});
							// #endif
							// #ifdef MP
							openBargainSubscribe()
								.then(res => {
									uni.hideLoading();
									uni.navigateTo({
										url: '/pages/activity/assist_detail/index?id=' + id
									});
								})
								.catch(err => {
									uni.hideLoading();
								});
							// #endif
						})
						.catch(err => {
							uni.showToast({
								title: err,
								icon: 'none'
							});
						});
				} else {
					// #ifdef H5 || APP-PLUS
					toLogin();
					// #endif
					// #ifdef MP
					this.$emit('isShowAuth', true);
					this.$emit('isAuto', true);
					// #endif
				}
			});
		},


		/**
		 * 获取个人用户信息
		 */
		getUserInfo: function() {
			let that = this;
			getUserInfo().then(res => {
				that.userInfo = res.data;
			});
		},
		// 品牌好店
		storeMerchant() {
			storeMerchantList({
				page: 1,
				limit: 3,
				is_best: 1
			}).then(res => {
				this.brandList = res.data.list;
			});
		},
		// 获取秒杀截止时间
		getSpeckillCutTime() {
			getSeckillIndexTime().then(res => {
				this.datatime = res.data.seckillEndTime;
			});
		},
		// 获取秒杀商品
		getSpikeProduct() {
			let that = this;
			getSeckillList({
				limit: 10
			})
				.then(res => {
					that.spikeList = res.data.list;
					that.spikeList.map(item => {
						item.sales = item.stock === 0 ? '0%' : ((item.sales * 100) / item.stock).toFixed(2) + '%';
					});
				})
				.catch(e => {});
		},
		// #ifdef MP
		// 直播
		getLiveList() {
			let that = this;
			getLiveList({
				limit: 10
			})
				.then(res => {
					that.liveList = res.data.list;
					that.liveList.forEach(val => {
						val.link =
							(val.live_status == 103 && val.replay_status) || val.live_status === 101 || val.live_status === 102
								? 'plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=' + val.room_id
								: '';
					});
				})
				.catch(e => {});
		},
		// #endif
		// 拼团
		getCombinationProduct() {
			let that = this;
			getCombinationList({
				limit: 3
			})
				.then(res => {
					that.combinationList = res.data.list;
				})
				.catch(e => {});
		},
		// 预售
		getPresellProduct() {
			let that = this;
			getPresellList({
				limit: 10
			})
				.then(res => {
					that.presellList = res.data.list;
				})
				.catch(e => {});
		},
		// 助力
		getAssistProduct() {
			let that = this;
			getAssistList({
				limit: 10
			})
				.then(res => {
					that.assistList = res.data.list;
				})
				.catch(e => {});
		},
		// 获取已助力成功数据
		getAssistUserCount() {
			let that = this;
			assistUserData()
				.then(res => {
					that.assistUserCount = res.data.count;
					that.assistUserList = res.data.list;
				})
				.catch(e => {});
		},
		handleAssist(id) {
			if (this.isLogin) {
				initiateAssistApi(id)
					.then(res => {
						let id = res.data.product_assist_set_id;
						uni.hideLoading();
						// #ifndef MP
						uni.navigateTo({
							url: '/pages/activity/assist_detail/index?id=' + id
						});
						// #endif
						// #ifdef MP
						openBargainSubscribe()
							.then(res => {
								uni.hideLoading();
								uni.navigateTo({
									url: '/pages/activity/assist_detail/index?id=' + id
								});
							})
							.catch(err => {
								uni.hideLoading();
							});
						// #endif
					})
					.catch(err => {
						uni.showToast({
							title: err,
							icon: 'none'
						});
					});
			} else {
				// #ifdef H5 || APP-PLUS
				toLogin();
				// #endif
				// #ifdef MP
				this.isAuto = true;
				this.$set(this, 'isShowAuth', true);
				// #endif
			}
		},
		// swiper
		swiperChange(e) {
			// this.swiperCur = e.detail.current
			let { current, source } = e.detail;
			if (source === 'autoplay' || source === 'touch') {
				//根据官方 source 来进行判断swiper的change事件是通过什么来触发的，autoplay是自动轮播。touch是用户手动滑动。其他的就是未知问题。抖动问题主要由于未知问题引起的，所以做了限制，只有在自动轮播和用户主动触发才去改变current值，达到规避了抖动bug
				this.swiperCur = e.detail.current;
			}
		},
		// 记录会员访问
		setVisit() {
			setVisit({
				url: '/pages/index/index'
			}).then(res => {
				console.log(res);
			});
		},
		// 导航分类切换
		changeTab(e) {
			let self = this;
			if (this.navIndex == e.index) return;
			this.navIndex = e.index;
			if (e.index > 0) {
				storeCategory({
					pid: e.pid
				}).then(res => {
					this.sortList = res.data.length > 9 ? res.data.splice(0, 9) : res.data;
					if (this.sortList.length > 0) {
						this.where.pid = e.pid;
						this.where.page = 1;
						this.loadend = false;
						this.loading = false;
						this.sortProduct = [];
						this.get_product_list();
					}
				});

				// #ifdef MP || APP-PLUS
				setTimeout(res => {
					let info = uni.createSelectorQuery().select('.mp-header');
					info
						.boundingClientRect(function(data) {
							//data - 各种参数
							self.sortMarTop = data.height + 10;

							console.log(self.sortMarTop, 'self.sortMarTop');
						})
						.exec();
				}, 0);
				// #endif
				// #ifdef H5
				self.sortMarTop = 10;
				// #endif
			}
		},
		//分类产品
		get_product_list: function() {
			console.log(123);
			let that = this;
			// if (!that.loadend) return;
			if (that.loading) return;
			that.loading = true;
			that.loadTitle = '';
			getProductslist(that.where)
				.then(res => {
					let list = res.data.list;
					let productList = that.$util.SplitArray(list, that.sortProduct);
					let loadend = list.length < that.where.limit;
					that.loadend = loadend;
					that.loading = false;
					that.loadTitle = loadend ? '已全部加载' : '加载更多';
					that.$set(that, 'sortProduct', productList);
					that.$set(that.where, 'page', that.where.page + 1);
				})
				.catch(err => {
					that.loading = false;
					that.loadTitle = '加载更多';
				});
		},
		/**
		 * 获取我的推荐
		 */
		get_host_product: function() {
			let that = this;
			let num = that.hotLimit;
			if (!that.hotScroll) return;
			if (that.hotLoading) return;
			that.hotLoading = true;
			that.hotTitle = '';
			getProductHot(that.hotPage, that.hotLimit).then(res => {
				let list = res.data.list;
				let productList = that.$util.SplitArray(list, that.hostProduct);
				let hotScroll = list.length <= num && list.length != 0;
				that.hotScroll = hotScroll;
				that.hotLoading = false;
				that.hotTitle = !hotScroll ? '已全部加载' : '加载更多';
				that.$set(that, 'hostProduct', productList);
				that.$set(that, 'hotPage', that.hotPage + 1);
			});
		},
		// 首页数据
		getIndexConfig: function() {
			let that = this;
			getIndexData().then(res => {
				that.$set(that, 'imgUrls', res.data.banner);
				that.$set(that, 'menus', res.data.menu);
				that.$set(that, 'hot', res.data.hot);
				that.$set(that, 'ad', res.data.ad);
				res.data.category.unshift({
					cate_name: '首页'
				});
				that.$set(that, 'navTop', res.data.category);

				that.lovely = res.data.lovely;
				that.$set(that, 'pageInfo', res.data);
				that.$set(that, 'likeInfo', res.data.likeInfo);
				that.$set(that, 'benefit', res.data.benefit);
				that.explosiveMoney = res.data.explosive_money;
				// #ifdef H5
				that.subscribe = res.data.subscribe;
				// #endif
				// 小程序判断用户是否授权；
				// #ifdef MP
				uni.getSetting({
					success(res) {
						if (!res.authSetting['scope.userInfo']) {
							that.window = that.couponList.length ? true : false;
						} else {
							that.window = false;
							that.iShidden = true;
						}
					}
				});
				// #endif
				// #ifndef MP
				if (that.isLogin) {
					that.window = false;
				} else {
					that.window = that.couponList.length ? true : false;
				}
				// #endif

				that.syncHeight();
			});
		},
		// 砍价详情
		bargDetail(item) {
			if (!this.isLogin) {
				// #ifdef H5
				uni.showModal({
					title: '提示',
					content: '您未登录，请登录！',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/users/login/index'
							});
						} else if (res.cancel) {
						}
					}
				});
				// #endif
				// #ifdef MP
				this.$set(this, 'isAuto', true);
				this.$set(this, 'isShowAuth', true);
				// #endif
			} else {
				uni.navigateTo({
					url: `/pages/activity/goods_bargain_details/index?id=${item.id}&bargain=${this.uid}`
				});
			}
		},
		// 授权关闭
		authColse: function(e) {
			this.isShowAuth = e;
		},
		// 首发新品详情
		goDetail(item) {
			if (item.activity && item.activity.type === '2' && !this.isLogin) {
				// #ifdef H5
				uni.showModal({
					title: '提示',
					content: '您未登录，请登录！',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/users/login/index'
							});
						} else if (res.cancel) {
						}
					}
				});
				// #endif
				// #ifdef MP
				this.$set(this, 'isAuto', true);
				this.$set(this, 'isShowAuth', true);
				// #endif
				return;
			} else {
				goShopDetail(item, this.uid).then(res => {
					uni.navigateTo({
						url: `/pages/goods_details/index?id=${item.id}`
					});
				});
			}
		},
		// 分类详情
		godDetail(item) {
			uni.navigateTo({
				url: `/pages/goods_details/index?id=${item.id}`
			});
		},
		//拼团详情
		goCombinDetail(item) {
			uni.navigateTo({
				url: `/pages/activity/combination_details/index?id=${item.product_group_id}`
			});
		},
		countTime: function() {
			// 获取当前时间
			var date = new Date();
			var now = date.getTime();
			//设置截止时间
			var endDate = new Date('2020-10-22 23:23:23');
			var end = endDate.getTime();
			//时间差
			var leftTime = end - now;
			//定义变量 d,h,m,s保存倒计时的时间
			if (leftTime >= 0) {
				this.d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
				this.h = Math.floor((leftTime / 1000 / 60 / 60) % 24);
				this.m = Math.floor((leftTime / 1000 / 60) % 60);
				this.s = Math.floor((leftTime / 1000) % 60);
				this.sum_h = this.d * 24 + this.h;
			}
			// console.log(this.h)
			// console.log(this.m)
			// console.log(this.s)
			// console.log(this.s);
			//递归每秒调用countTime方法，显示动态时间效果
			setTimeout(this.countTime, 1000);
		},
		//#ifdef H5
		ShareInfo(datas) {
			let data = this.storeInfo;
			let href = location.href;
			if (this.$wechat.isWeixin()) {
				if (this.isLogin) {
					href = href.indexOf('?') === -1 ? href + '?spid=' + this.uid : href + '&spid=' + this.uid;
				} else {
					href = href;
				}
				let configAppMessage = {
					desc: datas.share_info,
					title: datas.share_title,
					link: href,
					imgUrl: datas.share_pic
				};

				this.$wechat
					.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareAppMessage', 'onMenuShareTimeline'], configAppMessage)
					.then(res => {
						console.log(res, '=============================>>WXAPI');
					})
					.catch(err => {
						console.log(err);
					});
			}
		},
		//#endif

	},
	mounted() {
		let self = this;
		// #ifdef H5
		// 获取H5 搜索框高度
		let appSearchH = uni.createSelectorQuery().select('.serch-wrapper');
		appSearchH
			.boundingClientRect(function(data) {
				self.searchH = data.height;
			})
			.exec();
		// #endif
	},
	// 滚动到底部
	onReachBottom() {
		console.log('到底了');
		if (this.navIndex == 0) {
			// 首页加载更多
			this.get_host_product();
		} else {
			// 分类栏目加载更多
			if (this.sortProduct.length > 0) {
				this.get_product_list();
			} else {
				this.get_host_product();
			}
		}
	},
	// 滚动监听
	onPageScroll(e) {
		// #ifdef H5
		let self = this;
		if (e.scrollTop >= self.searchH) {
			self.isFixed = true;
		} else {
			self.isFixed = false;
		}
		// #endif
	}
};
</script>
<style>
page {
	display: flex;
	flex-direction: column;
	height: 100%;
	/* #ifdef H5 */
	background-color: #fff;
	/* #endif */
}
</style>
<style lang="scss">
	@import './index.scss';
</style>
